package com.zkingsoft.actions.admin;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.model.PaginationVO;
import com.zkingsoft.model.Player;
import com.zkingsoft.model.Team;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.PlayerService;
import com.zkingsoft.services.TeamService;

/**
 * @project MatrixCms
 * @package com.zkingsoft.actions.admin
 * @class PlayerController.java
 * @author Matrix-J E-mail:<935090232@qq.com>
 * @date 2016年4月21日10:31
 * @description 球员管理
 */
@Controller
@RequestMapping(value = "/admin/player")
public class PlayerController extends BaseController {

	private static final Logger log = Logger.getLogger(PlayerController.class);

	@Resource
	private PlayerService currentService;
	@Resource
	private TeamService teamService;

	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(HttpServletRequest request, Player player, PaginationVO pageVo) {
		log.info("按钮列表...");
		//referee.setCompanyId(getMe(request).getCompanyId());
		return showList(currentService, player, pageVo);
	}

	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(Player player) {
		if (player.getId() != null) {
			return modify(currentService, player, "球员");
		} else {
			player.setCreateTime(new Date());
			return add(currentService, player, "球员");
		}
	}

	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}

	@RequestMapping(value = "/editForm")
	public String editForm(Long id, HttpServletRequest request) {
		Player player;
		if (id != null) {
			player = currentService.findById(id);
			request.setAttribute("obj", player);
		}
		try {
			List<Team> list = teamService.findByModel(null);
			if(list!=null&&list.size()>0){
				request.setAttribute("list", list);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "admin/player-form";
	}

	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all(HttpServletRequest request) {
		Player player = new Player();
		//referee.setCompanyId(getMe(request).getCompanyId());
		return findByModel(currentService, player);
	}
}